<?
##########################################################################
#		DOCUMENTATION
##########################################################################
# Class that extends the rootclass. This module will provide the methods
# needed to render the book page.
#
# © LiberLab group, 2011
##########################################################################

require_once("base/root.php");

class Renderer extends Root{
	public function __construct() {
		parent::__construct("book");
	}
	
	public function main(){		
		require_once("dataStructure/book.php");
		$bookClass = new Book();
		$bookObj = $bookClass->getImportantBookData($this->selected);
		if ($bookObj == null){
			$pageToLoad = "404";
		}else{
			$bookImgPath = $this->getCover($this->selected, $bookObj->coverExtension);
			$title = $bookObj->title;
			$authors = $bookObj->authors;
			$content = $bookObj->content;
			$ucTitle = ucfirst($title);
			$temp = str_replace("__path__", $bookImgPath, $this->messages["bookImgSource"]);
			$temp = str_replace("__title__", $ucTitle, $temp);
			$content = str_replace("__bookImage__", $temp, $content);
			$this->tagHash["content"] = $content;
			$this->tagHash["bookTitle"] = $ucTitle;
			$this->tagHash["authors"] = $authors;
			$this->tagHash["imgCoverSrc"] = $bookImgPath;
			$this->tagHash["imgCoverAlt"] = str_replace("__title__", $title, $this->messages["altText"]);
		}
		$render = $this->render();
		# views++ (the database value)
		$bookClass->viewsPlusOne($this->selected);
	
		return $render;
	}

	public function __destruct() {
		parent::__destruct();
	}
};

?>
